package com.mybatis.session;

import com.mybatis.config.Configuration;
import com.mybatis.executor.Executor;
import com.mybatis.executor.SimpleExecutor;
import com.mybatis.resultset.DefaultResultSetHandler;

/**
 * @author luoc
 * @version 1.0
 * @date 2021/2/20 11:09
 * @since 1.0
 */
public class DefaultSqlSessionFactory implements SqlSessionFactory {

    private Configuration configuration;

    public DefaultSqlSessionFactory(Configuration configuration) {
        this.configuration = configuration;
    }


    public Configuration getConfiguration() {
        return configuration;
    }

    public SqlSession openSqlSession() {
        Executor executor = new SimpleExecutor(configuration.getJdbcProperties(),new DefaultResultSetHandler());
        SqlSession sqlSession = new DefaultSqlSession(configuration, executor);
        return sqlSession;
    }

    public void setConfiguration(Configuration configuration) {
        this.configuration = configuration;
    }
}
